package Collection;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author wuhan
 * @date 2019/9/28 21:47
 */
public class MapTest {

    public static class MyCompareByName implements Comparator<Student>{
        @Override
        public int compare(Student o1, Student o2) {
            int num=o1.getName().compareTo(o2.getName());
            if (num==0)
                return Integer.compare(o1.getAge(),o2.getAge());
            return num;
        }
    }
    public static void main(String[] args) {
        TreeMap<Student,String> tm= new TreeMap<>(new MyCompareByName());
        tm.put(new Student("wuhan",20),"北京");        tm.put(new Student("wuhan",21),"北京");

        tm.put(new Student("wuhan1",202),"北京");
        tm.put(new Student("wuhan2",203),"北京");
        tm.put(new Student("wuhan3",204),"北京");
        tm.put(new Student("wuhan4",203),"北京");
        tm.put(new Student("a",203),"北京");

        for (Map.Entry<Student, String> studentStringEntry : tm.entrySet()) {
            System.out.println(studentStringEntry);
        }

    }
}
